package com.zhihao.zhihaopicturebackend.common;

import com.zhihao.zhihaopicturebackend.exception.ErrorCode;
import lombok.Data;

import java.io.Serializable;

/**
 * @author Jackson
 * @create 2024/12/19 13:51
 * @description 全局响应封装类
 */
@Data
public class BaseResponse<T> implements Serializable {  // 能够在不同场景中反/序列化

    private int code;

    private T data;

    private String message;

    public BaseResponse(int code, T data, String message) {
        this.code = code;
        this.data = data;
        this.message = message;
    }

    public BaseResponse(int code, T data) {
        this(code, data, "");   // this-当前类BaseResponse
    }

    public BaseResponse(ErrorCode errorCode) {
        this(errorCode.getCode(), null, errorCode.getMessage());
    }

}
